<?php
/**
 * 任务审核处理
 * @author ice <iceinto@mallog.com.cn>
 *
 */
class TaskAuditModel extends BaseModel
{
	/**
	 * Get waiting for audit
	 * @return Array
	 * @author ice <iceinto@mallog.com.cn>
	 */
	public function getList($status = 6){
		$TaskModel = D('Task');
		$TaskAuditReturnModel = D('TaskAuditReturn');
		$map = array();
		$tasks = array();
		$map['status'] = $status;
		$queueTasks = D('Queue')->getListByWhere($map, 'tid');
		foreach($queueTasks as $task){
			$t = $TaskModel->getById($task['tid'], 'id,title');
			//Get back to information
			unset($map);
			$map['tid'] = $task['tid'];
			$count = $TaskAuditReturnModel->where($map)->count();
			if($count){
				$returns[] = $t;
			}else{
				$tasks[] = $t;
			}
		}
		return array('tasks' => $tasks, 'returns' => $returns);
	}

	/**
	 * Add one task audit
	 * @param int $uid user id
	 * @param int $tid task id
	 * @param string $remark
	 * @return int
	 * @author ice <iceinto@mallog.com.cn>
	 */
	public function addOne($uid, $tid, $remark){
		$data = array();
		$data['create_time'] = time();
		$data['uid'] = $uid;
		$data['tid'] = $tid;
		$data['remark'] = $remark;
		return $this->add($data);
	}
}